package jsyf.oa.dao.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.task.YzmEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

/**
 * Created by y on 2018/6/5.
 */
@Repository
public class YzmDao extends BaseDao {
    public YzmDao() {
        super.iBaseEntity=new YzmEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, YzmEntity.class);
    }

    public JSONObject checkAndYzm(String userId){
        StringBuffer sql=new StringBuffer();
        sql.append(" SELECT yzm,TIMESTAMPDIFF(SECOND,(select CREATE_TIME from t_sys_yzm WHERE USER_ID =? ORDER BY CREATE_TIME desc limit 0,1),NOW()) as second FROM t_sys_yzm");
        sql.append(" WHERE USER_ID =?");
        sql.append(" ORDER BY CREATE_TIME DESC LIMIT 0,1");
        return super.queryForJsonObject(sql.toString(),new Object[]{userId,userId});
    }
}
